package com.pug.web.index;

import com.alibaba.fastjson.JSONObject;
import com.pug.annotation.EnableNoToken;
import com.pug.pojo.Advice;
import com.pug.pojo.Banner;
import com.pug.pojo.Category;
import com.pug.service.advice.AdviceServiceImpl;
import com.pug.service.banner.BannerServiceImpl;
import com.pug.service.category.CategoryServiceImpl;
import com.pug.web.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author: lqm
 * create: 2022/4/29 20:31
 * Lover: lqx
 *
 * @see
 */
@RestController
public class IndexController extends BaseController {
    @Resource
    AdviceServiceImpl adviceService;
    @Resource
    BannerServiceImpl bannerService;
    @Resource
    CategoryServiceImpl categoryService;
    //查询首页轮播图，通知，分类，通过jsonObject
    @PostMapping("/index/load")
    @EnableNoToken(true)
    JSONObject getIndexData(){
        // 首页查询加入线程池
//        ThreadPoolExecutor tpe = new ThreadPoolExecutor(3, 6, 50, TimeUnit.MILLISECONDS, bq);

        List<Advice> indexAdvice = adviceService.findIndexAdvice(1, 6);
        List<Banner> indexBanner = bannerService.findIndexBaner(1, 6);
        List<Category> categories = categoryService.findCategories();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("bannerList",indexBanner);
        jsonObject.put("categoryList",categories);
        jsonObject.put("adviceList",indexAdvice);
        return jsonObject;
    }
}
